<template>
  <div id="payment">
    <div :class="['alertTitel', { bigalertTitel: showalertTitel }]">
      请选择地址
    </div>
    <Address v-if="show"></Address>
    <div class="payment-top">
      <div>订单确认</div>
      <div>
        <span>我的购物车</span>- <span>填写订单信息</span>-<span>完成订单</span>
      </div>
    </div>
    <h3>配送信息</h3>
    <div class="content">
      <div class="content-top">
        <span>请添加地址</span>
        <span @click="selectAddress" id="selectAddress">选择地址</span>
      </div>
      <div class="content-time">
        <span>配送时间</span>
        <span> 请选择日期：<input type="date" name="" id="" /> </span>
        <span> 请选择时间：<input type="time" name="" id="" /> </span>
        <span
          >配送时间10:00-19:30;截单时间14:00;9:00至14:00下单,最早14:00配送;14:00至21:30下单,最早次日10:00配送;21:30至次日9:00下单,最早次日14:00配送;配送当天不可修改配送时间;实际配送可能会有30分钟左右误差;人工审单存在时效性，13:45-14:00之间的订单有可能影响当天配送时效，敬请谅解。</span
        >
      </div>
      <div class="content-goods">
        <div v-for="item in paygoods" :key="item.goods_id" class="goodsBox">
          <img :src="$store.state.url + item.goods_coverimg" />

          <span>
            <h4>{{ item.goods_name }}</h4>
            <p>{{ item.goods_english }}</p>
          </span>
          <span>×{{ item.goods_count }}</span>
          <span>￥{{ item.goods_price }}</span>
        </div>
      </div>
    </div>
    <div class="btm">
      <div>
        <h3>合计：￥{{ totel.toFixed(2) }}</h3>
        <div @click="submitOder">提交订单</div>
      </div>
    </div>
  </div>
</template>
<script>
import Address from "./Address/Address.vue";
export default {
  components: {
    Address,
  },
  data() {
    return {
      paygoods: [],
      showalertTitel: false,
      totel: "",
      show: false,
    };
  },

  mounted() {
    let res = this.$store.state.userCar;
    this.paygoods = res.filter((el) => {
      return el.flag == true;
    });
    this.totel = this.paygoods.reduce((a, b) => {
      return b.goods_price * b.goods_count + a;
    }, 0);
  },
  methods: {
    selectAddress() {
      this.show = !this.show;
    },
    submitOder() {
      if (this.$store.state.isAddress) {
        this.$store.commit("changeUserCar",this.paygoods)
        this.$router.push("/order")
      } else {
        this.showalertTitel = true;
        setTimeout(() => {
          this.showalertTitel = false;
        }, 1000);
      }
    },
  },
};
</script>
<style lang="scss" scoped>
#payment {
  margin-top: 120px;
  width: 100%;
  background-color: #f8f8f8;
  h3 {
    width: 92%;
    margin: 0 auto;
  }
}
.alertTitel {
  position: fixed;
  width: 200px;
  height: 50px;
  text-align: center;
  color: white;
  line-height: 50px;
  background-color: rgba(0, 0, 0, 0.8);
  left: 40%;
  top: 40%;
  transform: scale(0);
}
.bigalertTitel {
  transform: scale(1);
}
.payment-top {
  width: 92%;
  margin: 0 auto;
  display: flex;
  height: 150px;
  line-height: 150px;
  justify-content: space-between;
  div:first-child {
    font-size: 30px;
  }
  div:last-child {
    span {
      margin-right: 20px;
    }
  }
}
.content {
  width: 92%;
  background-color: white;
  margin: 20px auto;
  .content-top {
    height: 150px;
    line-height: 150px;
    font-size: 20px;
    display: flex;
    border-bottom: 1px solid rgb(224, 221, 221);
    justify-content: space-between;
    align-items: center;
    margin-bottom: 40px;
    span:last-child {
      width: 150px;
      height: 50px;
      line-height: 50px;
      text-align: center;
      border-radius: 20px;
      background-color: #ffe100;
    }
  }
  div:not(.goodsBox) {
    margin: 20px 50px;
  }
}
.content-time {
  span:first-child {
    font-size: 18px;
    font-weight: bolder;
    margin-right: 20px;
  }
  span {
    margin-right: 20px;
    height: 50px;
    line-height: 50px;
    width: 150px;
    vertical-align: top;
  }
  span:last-child {
    display: inline-block;
    height: 50px;
    line-height: 25px;
    overflow-y: auto;
    font-weight: 20;
    margin-left: 20px;
    width: 50%;
  }
}
.content-goods {
  width: 92%;
  margin: 0 auto;
  background-color: white;
  padding-bottom: 10px;
}
.goodsBox {
  display: flex;
  width: 100%;
  justify-content: space-between;
  margin-bottom: 20px;
  img {
    width: 180px;
  }
  span {
    line-height: 50px;
  }
}
.btm {
  width: 92%;
  height: 300px;
  margin: 0 auto;
  display: flex;
  justify-content: flex-end;
  background-color: #f8f8f8;
  div {
    height: 300px;
    margin-right: 40px;
    margin-top: 40px;
    white-space: nowrap;
    div {
      width: 120px;
      height: 50px;
      background-color: #ffe100;
      text-align: center;
      line-height: 50px;
      border-radius: 20px;
    }
    div:hover {
      cursor: pointer;
    }
  }
}
#selectAddress:hover {
  cursor: pointer;
}
</style>